home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / file-tra / wu-ftpd-.000 / wu-ftpd- / wu-ftpd-2.4-fixed / src / ftpcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-13  |  74.1 KB  |  2,618 lines

  1.  
  2. /*  A Bison parser, made from ftpcmd.y with Bison version GNU Bison version 1.22
  3.   */
  4.  
  5. #define YYBISON 1  /* Identify Bison output.  */
  6.  
  7. #define    A    258
  8. #define    B    259
  9. #define    C    260
  10. #define    E    261
  11. #define    F    262
  12. #define    I    263
  13. #define    L    264
  14. #define    N    265
  15. #define    P    266
  16. #define    R    267
  17. #define    S    268
  18. #define    T    269
  19. #define    SP    270
  20. #define    CRLF    271
  21. #define    COMMA    272
  22. #define    STRING    273
  23. #define    NUMBER    274
  24. #define    USER    275
  25. #define    PASS    276
  26. #define    ACCT    277
  27. #define    REIN    278
  28. #define    QUIT    279
  29. #define    PORT    280
  30. #define    PASV    281
  31. #define    TYPE    282
  32. #define    STRU    283
  33. #define    MODE    284
  34. #define    RETR    285
  35. #define    STOR    286
  36. #define    APPE    287
  37. #define    MLFL    288
  38. #define    MAIL    289
  39. #define    MSND    290
  40. #define    MSOM    291
  41. #define    MSAM    292
  42. #define    MRSQ    293
  43. #define    MRCP    294
  44. #define    ALLO    295
  45. #define    REST    296
  46. #define    RNFR    297
  47. #define    RNTO    298
  48. #define    ABOR    299
  49. #define    DELE    300
  50. #define    CWD    301
  51. #define    LIST    302
  52. #define    NLST    303
  53. #define    SITE    304
  54. #define    STAT    305
  55. #define    HELP    306
  56. #define    NOOP    307
  57. #define    MKD    308
  58. #define    RMD    309
  59. #define    PWD    310
  60. #define    CDUP    311
  61. #define    STOU    312
  62. #define    SMNT    313
  63. #define    SYST    314
  64. #define    SIZE    315
  65. #define    MDTM    316
  66. #define    UMASK    317
  67. #define    IDLE    318
  68. #define    CHMOD    319
  69. #define    GROUP    320
  70. #define    GPASS    321
  71. #define    NEWER    322
  72. #define    MINFO    323
  73. #define    INDEX    324
  74. #define    EXEC    325
  75. #define    ALIAS    326
  76. #define    CDPATH    327
  77. #define    GROUPS    328
  78. #define    LEXERR    329
  79.  
  80. #line 41 "ftpcmd.y"
  81.  
  82.  
  83. #ifndef lint
  84. static char sccsid[] = "@(#)ftpcmd.y    5.24 (Berkeley) 2/25/91";
  85. #endif /* not lint */
  86.  
  87. #include "config.h"
  88. #include <sys/param.h>
  89. #include <sys/types.h>
  90. #include <sys/socket.h>
  91. #include <sys/stat.h>
  92. #include <netinet/in.h>
  93. #include <arpa/ftp.h>
  94. #include <stdio.h>
  95. #include <signal.h>
  96. #include <ctype.h>
  97. #include <pwd.h>
  98. #include <setjmp.h>
  99. #ifdef SYSSYSLOG
  100. #include <sys/syslog.h>
  101. #else
  102. #include <syslog.h>
  103. #endif
  104. #include <time.h>
  105. #include <string.h>
  106. #include <limits.h>
  107. #include "support/ftw.h"
  108. #include "extensions.h"
  109. #include "pathnames.h"
  110.  
  111. extern  int dolreplies;
  112. extern  char ls_long[50];
  113. extern  char ls_short[50];
  114. extern  struct sockaddr_in data_dest;
  115. extern  int logged_in;
  116. extern  struct passwd *pw;
  117. extern  int anonymous;
  118. extern  int logging;
  119. extern  int log_commands;
  120. extern  int type;
  121. extern  int form;
  122. extern  int debug;
  123. extern  int timeout;
  124. extern  int maxtimeout;
  125. extern  int pdata;
  126. extern  char hostname[], remotehost[];
  127. #ifdef SETPROCTITLE
  128. extern  char proctitle[];
  129. #endif
  130. extern  char *globerr;
  131. extern  int usedefault;
  132. extern  int transflag;
  133. extern  char tmpline[];
  134. extern  int data;
  135. char    **ftpglob();
  136. off_t   restart_point;
  137.  
  138. extern  char    *strunames[];
  139. extern  char    *typenames[];
  140. extern  char    *modenames[];
  141. extern  char    *formnames[];
  142.  
  143. static  int cmd_type;
  144. static  int cmd_form;
  145. static  int cmd_bytesz;
  146. char    cbuf[512];
  147. char    *fromname;
  148.  
  149. static void toolong();
  150.  
  151. #define CMD 0   /* beginning of command */
  152. #define ARGS    1   /* expect miscellaneous arguments */
  153. #define STR1    2   /* expect SP followed by STRING */
  154. #define STR2    3   /* expect STRING */
  155. #define OSTR    4   /* optional SP then STRING */
  156. #define ZSTR1   5   /* SP then optional STRING */
  157. #define ZSTR2   6   /* optional STRING after SP */
  158. #define SITECMD 7   /* SITE command */
  159. #define NSTR    8   /* Number followed by a string */
  160. #define STR3    9   /* expect STRING followed by optional SP then STRING */
  161.  
  162. struct tab {
  163.     char    *name;
  164.     short   token;
  165.     short   state;
  166.     short   implemented;    /* 1 if command is implemented */
  167.     char    *help;
  168. };
  169.  
  170. struct tab cmdtab[] = {     /* In order defined in RFC 765 */
  171.     { "USER", USER, STR1, 1,    "<sp> username" },
  172.     { "PASS", PASS, ZSTR1, 1,   "<sp> password" },
  173.     { "ACCT", ACCT, STR1, 0,    "(specify account)" },
  174.     { "SMNT", SMNT, ARGS, 0,    "(structure mount)" },
  175.     { "REIN", REIN, ARGS, 0,    "(reinitialize server state)" },
  176.     { "QUIT", QUIT, ARGS, 1,    "(terminate service)", },
  177.     { "PORT", PORT, ARGS, 1,    "<sp> b0, b1, b2, b3, b4" },
  178.     { "PASV", PASV, ARGS, 1,    "(set server in passive mode)" },
  179.     { "TYPE", TYPE, ARGS, 1,    "<sp> [ A | E | I | L ]" },
  180.     { "STRU", STRU, ARGS, 1,    "(specify file structure)" },
  181.     { "MODE", MODE, ARGS, 1,    "(specify transfer mode)" },
  182.     { "RETR", RETR, STR1, 1,    "<sp> file-name" },
  183.     { "STOR", STOR, STR1, 1,    "<sp> file-name" },
  184.     { "APPE", APPE, STR1, 1,    "<sp> file-name" },
  185.     { "MLFL", MLFL, OSTR, 0,    "(mail file)" },
  186.     { "MAIL", MAIL, OSTR, 0,    "(mail to user)" },
  187.     { "MSND", MSND, OSTR, 0,    "(mail send to terminal)" },
  188.     { "MSOM", MSOM, OSTR, 0,    "(mail send to terminal or mailbox)" },
  189.     { "MSAM", MSAM, OSTR, 0,    "(mail send to terminal and mailbox)" },
  190.     { "MRSQ", MRSQ, OSTR, 0,    "(mail recipient scheme question)" },
  191.     { "MRCP", MRCP, STR1, 0,    "(mail recipient)" },
  192.     { "ALLO", ALLO, ARGS, 1,    "allocate storage (vacuously)" },
  193.     { "REST", REST, ARGS, 1,    "(restart command)" },
  194.     { "RNFR", RNFR, STR1, 1,    "<sp> file-name" },
  195.     { "RNTO", RNTO, STR1, 1,    "<sp> file-name" },
  196.     { "ABOR", ABOR, ARGS, 1,    "(abort operation)" },
  197.     { "DELE", DELE, STR1, 1,    "<sp> file-name" },
  198.     { "CWD",  CWD,  OSTR, 1,    "[ <sp> directory-name ]" },
  199.     { "XCWD", CWD,  OSTR, 1,    "[ <sp> directory-name ]" },
  200.     { "LIST", LIST, OSTR, 1,    "[ <sp> path-name ]" },
  201.     { "NLST", NLST, OSTR, 1,    "[ <sp> path-name ]" },
  202.     { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" },
  203.     { "SYST", SYST, ARGS, 1,    "(get type of operating system)" },
  204.     { "STAT", STAT, OSTR, 1,    "[ <sp> path-name ]" },
  205.     { "HELP", HELP, OSTR, 1,    "[ <sp> <string> ]" },
  206.     { "NOOP", NOOP, ARGS, 1,    "" },
  207.     { "MKD",  MKD,  STR1, 1,    "<sp> path-name" },
  208.     { "XMKD", MKD,  STR1, 1,    "<sp> path-name" },
  209.     { "RMD",  RMD,  STR1, 1,    "<sp> path-name" },
  210.     { "XRMD", RMD,  STR1, 1,    "<sp> path-name" },
  211.     { "PWD",  PWD,  ARGS, 1,    "(return current directory)" },
  212.     { "XPWD", PWD,  ARGS, 1,    "(return current directory)" },
  213.     { "CDUP", CDUP, ARGS, 1,    "(change to parent directory)" },
  214.     { "XCUP", CDUP, ARGS, 1,    "(change to parent directory)" },
  215.     { "STOU", STOU, STR1, 1,    "<sp> file-name" },
  216.     { "SIZE", SIZE, OSTR, 1,    "<sp> path-name" },
  217.     { "MDTM", MDTM, OSTR, 1,    "<sp> path-name" },
  218.     { NULL,   0,    0,    0,    0 }
  219. };
  220.  
  221. struct tab sitetab[] = {
  222.     { "UMASK", UMASK, ARGS, 1,  "[ <sp> umask ]" },
  223.     { "IDLE",  IDLE,  ARGS, 1,  "[ <sp> maximum-idle-time ]" },
  224.     { "CHMOD", CHMOD, NSTR, 1,  "<sp> mode <sp> file-name" },
  225.     { "HELP",  HELP,  OSTR, 1,  "[ <sp> <string> ]" },
  226.     { "GROUP", GROUP, STR1, 1,  "<sp> access-group" },
  227.     { "GPASS", GPASS, STR1, 1,  "<sp> access-password" },
  228.     { "NEWER", NEWER, STR3, 1,  "<sp> YYYYMMDDHHMMSS [ <sp> path-name ]" },
  229.     { "MINFO", MINFO, STR3, 1,  "<sp> YYYYMMDDHHMMSS [ <sp> path-name ]" },
  230.     { "INDEX", INDEX, STR1, 1,  "<sp> pattern" },
  231.     { "EXEC",  EXEC,  STR1, 1,  "<sp> command [ <sp> arguments ]" },
  232.     { "ALIAS", ALIAS, OSTR, 1,  "[ <sp> alias ] " },
  233.     { "CDPATH", CDPATH, OSTR, 1,  "[ <sp> ] " },
  234.     { "GROUPS", GROUPS, OSTR, 1,  "[ <sp> ] " },
  235.     { NULL,    0,     0,    0,  0 }
  236. };
  237.  
  238. void
  239. print_groups();
  240.  
  241.  
  242.  
  243. #line 223 "ftpcmd.y"
  244. typedef union {
  245.     char    *String;
  246.     int     Number;
  247. } YYSTYPE;
  248.  
  249. #ifndef YYLTYPE
  250. typedef
  251.   struct yyltype
  252.     {
  253.       int timestamp;
  254.       int first_line;
  255.       int first_column;
  256.       int last_line;
  257.       int last_column;
  258.       char *text;
  259.    }
  260.   yyltype;
  261.  
  262. #define YYLTYPE yyltype
  263. #endif
  264.  
  265. #include <stdio.h>
  266.  
  267. #ifndef __cplusplus
  268. #ifndef __STDC__
  269. #define const
  270. #endif
  271. #endif
  272.  
  273.  
  274.  
  275. #define    YYFINAL        249
  276. #define    YYFLAG        -32768
  277. #define    YYNTBASE    75
  278.  
  279. #define YYTRANSLATE(x) ((unsigned)(x) <= 329 ? yytranslate[x] : 90)
  280.  
  281. static const char yytranslate[] = {     0,
  282.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  283.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  284.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  285.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  286.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  287.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  288.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  289.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  290.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  291.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  292.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  293.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  294.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  295.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  296.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  297.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  298.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  299.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  300.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  301.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  302.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  303.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  304.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  305.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  306.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  307.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  308.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  309.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  310.     26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
  311.     36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
  312.     46,    47,    48,    49,    50,    51,    52,    53,    54,    55,
  313.     56,    57,    58,    59,    60,    61,    62,    63,    64,    65,
  314.     66,    67,    68,    69,    70,    71,    72,    73,    74
  315. };
  316.  
  317. #if YYDEBUG != 0
  318. static const short yyprhs[] = {     0,
  319.      0,     1,     4,     7,    12,    17,    22,    25,    30,    35,
  320.     40,    45,    54,    60,    66,    72,    76,    82,    86,    92,
  321.     98,   101,   107,   112,   115,   119,   125,   128,   133,   136,
  322.    142,   148,   152,   156,   161,   168,   174,   182,   192,   197,
  323.    204,   212,   220,   228,   238,   248,   256,   264,   270,   273,
  324.    279,   285,   288,   291,   297,   302,   307,   314,   319,   324,
  325.    326,   327,   329,   331,   343,   345,   347,   349,   351,   355,
  326.    357,   361,   363,   365,   369,   372,   374,   376,   378,   380,
  327.    382,   384,   386,   388,   390
  328. };
  329.  
  330. static const short yyrhs[] = {    -1,
  331.     75,    76,     0,    75,    77,     0,    20,    15,    78,    16,
  332.      0,    21,    15,    79,    16,     0,    25,    15,    81,    16,
  333.      0,    26,    16,     0,    27,    15,    83,    16,     0,    28,
  334.     15,    84,    16,     0,    29,    15,    85,    16,     0,    40,
  335.     15,    19,    16,     0,    40,    15,    19,    15,    12,    15,
  336.     19,    16,     0,    30,    89,    15,    86,    16,     0,    31,
  337.     89,    15,    86,    16,     0,    32,    89,    15,    86,    16,
  338.      0,    48,    89,    16,     0,    48,    89,    15,    18,    16,
  339.      0,    47,    89,    16,     0,    47,    89,    15,    86,    16,
  340.      0,    50,    89,    15,    86,    16,     0,    50,    16,     0,
  341.     45,    89,    15,    86,    16,     0,    43,    15,    86,    16,
  342.      0,    44,    16,     0,    46,    89,    16,     0,    46,    89,
  343.     15,    86,    16,     0,    51,    16,     0,    51,    15,    18,
  344.     16,     0,    52,    16,     0,    53,    89,    15,    86,    16,
  345.      0,    54,    89,    15,    86,    16,     0,    55,    89,    16,
  346.      0,    56,    89,    16,     0,    49,    15,    51,    16,     0,
  347.     49,    15,    51,    15,    18,    16,     0,    49,    15,    62,
  348.     89,    16,     0,    49,    15,    62,    89,    15,    88,    16,
  349.      0,    49,    15,    64,    89,    15,    88,    15,    86,    16,
  350.      0,    49,    15,    63,    16,     0,    49,    15,    63,    15,
  351.     19,    16,     0,    49,    15,    65,    89,    15,    78,    16,
  352.      0,    49,    15,    66,    89,    15,    79,    16,     0,    49,
  353.     15,    67,    89,    15,    18,    16,     0,    49,    15,    67,
  354.     89,    15,    18,    15,    86,    16,     0,    49,    15,    68,
  355.     89,    15,    18,    15,    86,    16,     0,    49,    15,    69,
  356.     89,    15,    18,    16,     0,    49,    15,    70,    89,    15,
  357.     18,    16,     0,    57,    89,    15,    86,    16,     0,    59,
  358.     16,     0,    60,    89,    15,    86,    16,     0,    61,    89,
  359.     15,    86,    16,     0,    24,    16,     0,     1,    16,     0,
  360.     42,    89,    15,    86,    16,     0,    41,    15,    80,    16,
  361.      0,    49,    15,    71,    16,     0,    49,    15,    71,    15,
  362.     18,    16,     0,    49,    15,    73,    16,     0,    49,    15,
  363.     72,    16,     0,    18,     0,     0,    18,     0,    19,     0,
  364.     19,    17,    19,    17,    19,    17,    19,    17,    19,    17,
  365.     19,     0,    10,     0,    14,     0,     5,     0,     3,     0,
  366.      3,    15,    82,     0,     6,     0,     6,    15,    82,     0,
  367.      8,     0,     9,     0,     9,    15,    80,     0,     9,    80,
  368.      0,     7,     0,    12,     0,    11,     0,    13,     0,     4,
  369.      0,     5,     0,    87,     0,    18,     0,    19,     0,     0
  370. };
  371.  
  372. #endif
  373.  
  374. #if YYDEBUG != 0
  375. static const short yyrline[] = { 0,
  376.    236,   237,   242,   245,   251,   262,   272,   277,   313,   326,
  377.    339,   344,   349,   357,   365,   373,   379,   387,   396,   407,
  378.    415,   420,   428,   440,   445,   451,   459,   464,   480,   485,
  379.    493,   501,   507,   513,   518,   523,   534,   558,   583,   590,
  380.    603,   611,   619,   624,   630,   636,   649,   655,   663,   685,
  381.    703,   726,   732,   737,   750,   761,   766,   771,   776,   783,
  382.    786,   791,   794,   797,   810,   814,   818,   824,   829,   834,
  383.    839,   844,   848,   853,   859,   866,   870,   874,   880,   884,
  384.    888,   894,   913,   916,   941
  385. };
  386.  
  387. static const char * const yytname[] = {   "$","error","$illegal.","A","B","C",
  388. "E","F","I","L","N","P","R","S","T","SP","CRLF","COMMA","STRING","NUMBER","USER",
  389. "PASS","ACCT","REIN","QUIT","PORT","PASV","TYPE","STRU","MODE","RETR","STOR",
  390. "APPE","MLFL","MAIL","MSND","MSOM","MSAM","MRSQ","MRCP","ALLO","REST","RNFR",
  391. "RNTO","ABOR","DELE","CWD","LIST","NLST","SITE","STAT","HELP","NOOP","MKD","RMD",
  392. "PWD","CDUP","STOU","SMNT","SYST","SIZE","MDTM","UMASK","IDLE","CHMOD","GROUP",
  393. "GPASS","NEWER","MINFO","INDEX","EXEC","ALIAS","CDPATH","GROUPS","LEXERR","cmd_list",
  394. "cmd","rcmd","username","password","byte_size","host_port","form_code","type_code",
  395. "struct_code","mode_code","pathname","pathstring","octal_number","check_login",
  396. ""
  397. };
  398. #endif
  399.  
  400. static const short yyr1[] = {     0,
  401.     75,    75,    75,    76,    76,    76,    76,    76,    76,    76,
  402.     76,    76,    76,    76,    76,    76,    76,    76,    76,    76,
  403.     76,    76,    76,    76,    76,    76,    76,    76,    76,    76,
  404.     76,    76,    76,    76,    76,    76,    76,    76,    76,    76,
  405.     76,    76,    76,    76,    76,    76,    76,    76,    76,    76,
  406.     76,    76,    76,    77,    77,    77,    77,    77,    77,    78,
  407.     79,    79,    80,    81,    82,    82,    82,    83,    83,    83,
  408.     83,    83,    83,    83,    83,    84,    84,    84,    85,    85,
  409.     85,    86,    87,    88,    89
  410. };
  411.  
  412. static const short yyr2[] = {     0,
  413.      0,     2,     2,     4,     4,     4,     2,     4,     4,     4,
  414.      4,     8,     5,     5,     5,     3,     5,     3,     5,     5,
  415.      2,     5,     4,     2,     3,     5,     2,     4,     2,     5,
  416.      5,     3,     3,     4,     6,     5,     7,     9,     4,     6,
  417.      7,     7,     7,     9,     9,     7,     7,     5,     2,     5,
  418.      5,     2,     2,     5,     4,     4,     6,     4,     4,     1,
  419.      0,     1,     1,    11,     1,     1,     1,     1,     3,     1,
  420.      3,     1,     1,     3,     2,     1,     1,     1,     1,     1,
  421.      1,     1,     1,     1,     0
  422. };
  423.  
  424. static const short yydefact[] = {     1,
  425.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  426.     85,    85,    85,     0,     0,    85,     0,     0,    85,    85,
  427.     85,    85,     0,    85,     0,     0,    85,    85,    85,    85,
  428.     85,     0,    85,    85,     2,     3,    53,     0,    61,    52,
  429.      0,     7,     0,     0,     0,     0,     0,     0,     0,     0,
  430.      0,     0,    24,     0,     0,     0,     0,     0,    21,     0,
  431.      0,    27,    29,     0,     0,     0,     0,     0,    49,     0,
  432.      0,    60,     0,    62,     0,     0,     0,    68,    70,    72,
  433.     73,     0,    76,    78,    77,     0,    80,    81,    79,     0,
  434.      0,     0,     0,     0,    63,     0,     0,    83,     0,    82,
  435.      0,     0,    25,     0,    18,     0,    16,     0,    85,     0,
  436.     85,    85,    85,    85,    85,    85,    85,     0,     0,     0,
  437.      0,     0,     0,     0,    32,    33,     0,     0,     0,     4,
  438.      5,     0,     6,     0,     0,     0,    75,     8,     9,    10,
  439.      0,     0,     0,     0,    11,    55,     0,    23,     0,     0,
  440.      0,     0,     0,    34,     0,     0,    39,     0,     0,     0,
  441.      0,     0,     0,     0,     0,    56,    59,    58,     0,    28,
  442.      0,     0,     0,     0,     0,     0,    67,    65,    66,    69,
  443.     71,    74,    13,    14,    15,     0,    54,    22,    26,    19,
  444.     17,     0,     0,    36,     0,     0,     0,    61,     0,     0,
  445.      0,     0,     0,    20,    30,    31,    48,    50,    51,     0,
  446.      0,    35,    84,     0,    40,     0,     0,     0,     0,     0,
  447.      0,     0,    57,     0,     0,    37,     0,    41,    42,     0,
  448.     43,     0,    46,    47,     0,    12,     0,     0,     0,     0,
  449.     38,    44,    45,     0,     0,     0,    64,     0,     0
  450. };
  451.  
  452. static const short yydefgoto[] = {     1,
  453.     35,    36,    73,    75,    96,    77,   180,    82,    86,    90,
  454.     99,   100,   214,    46
  455. };
  456.  
  457. static const short yypact[] = {-32768,
  458.     48,   -12,    -8,    -3,    15,    19,    26,    39,    70,    95,
  459. -32768,-32768,-32768,    99,   108,-32768,   109,   100,-32768,-32768,
  460. -32768,-32768,   110,   111,    13,   112,-32768,-32768,-32768,-32768,
  461. -32768,   113,-32768,-32768,-32768,-32768,-32768,   114,   115,-32768,
  462.    107,-32768,    78,    34,    22,   116,   119,   120,   118,   130,
  463.    123,   132,-32768,   136,    24,    41,    51,   -48,-32768,   137,
  464.    135,-32768,-32768,   139,   140,   141,   142,   144,-32768,   145,
  465.    146,-32768,   147,-32768,   148,   149,   151,   150,   153,-32768,
  466.    -10,   154,-32768,-32768,-32768,   155,-32768,-32768,-32768,   156,
  467.    132,   132,   132,    55,-32768,   157,   132,-32768,   158,-32768,
  468.    132,   132,-32768,   132,-32768,   138,-32768,    67,-32768,    97,
  469. -32768,-32768,-32768,-32768,-32768,-32768,-32768,   102,   159,   160,
  470.    132,   161,   132,   132,-32768,-32768,   132,   132,   132,-32768,
  471. -32768,   143,-32768,   101,   101,   130,-32768,-32768,-32768,-32768,
  472.    162,   163,   164,   169,-32768,-32768,   166,-32768,   167,   168,
  473.    170,   171,   172,-32768,   104,   173,-32768,   174,   176,   178,
  474.    179,   180,   181,   182,   183,-32768,-32768,-32768,   184,-32768,
  475.    186,   187,   188,   189,   190,   152,-32768,-32768,-32768,-32768,
  476. -32768,-32768,-32768,-32768,-32768,   192,-32768,-32768,-32768,-32768,
  477. -32768,   193,   191,-32768,   195,   191,   114,   115,   194,   196,
  478.    197,   198,   201,-32768,-32768,-32768,-32768,-32768,-32768,   199,
  479.    200,-32768,-32768,   204,-32768,   206,   207,   208,   106,   210,
  480.    211,   212,-32768,   205,   213,-32768,   132,-32768,-32768,   132,
  481. -32768,   132,-32768,-32768,   214,-32768,   215,   216,   218,   209,
  482. -32768,-32768,-32768,   217,   220,   219,-32768,   185,-32768
  483. };
  484.  
  485. static const short yypgoto[] = {-32768,
  486. -32768,-32768,   -67,     0,   -73,-32768,    53,-32768,-32768,-32768,
  487.    -91,-32768,     3,    31
  488. };
  489.  
  490.  
  491. #define    YYLAST        238
  492.  
  493.  
  494. static const short yytable[] = {   141,
  495.    142,   143,   108,    37,   136,   147,    38,   137,    95,   149,
  496.    150,    39,   151,   109,   110,   111,   112,   113,   114,   115,
  497.    116,   117,   118,   119,   120,    87,    88,    61,    62,   169,
  498.     40,   171,   172,    41,    89,   173,   174,   175,   102,   103,
  499.     83,    42,    47,    48,    84,    85,    51,   248,     2,    54,
  500.     55,    56,    57,    43,    60,   104,   105,    64,    65,    66,
  501.     67,    68,   182,    70,    71,   106,   107,     3,     4,   144,
  502.    145,     5,     6,     7,     8,     9,    10,    11,    12,    13,
  503.     78,   153,   154,    79,    44,    80,    81,    14,    15,    16,
  504.     17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
  505.     27,    28,    29,    30,    31,   177,    32,    33,    34,    45,
  506.    178,   156,   157,    49,   179,    53,   165,   166,   193,   194,
  507.    230,   231,    50,    52,    58,    76,    59,    63,    69,   217,
  508.     91,    72,    74,    92,    93,   237,    94,    97,   238,   155,
  509.    239,   158,   159,   160,   161,   162,   163,   164,    95,    98,
  510.    101,   121,   122,   123,   124,   152,   125,   126,   127,   128,
  511.    129,   176,   130,   131,   134,   132,   133,   135,   210,   138,
  512.    139,   140,   146,   148,   167,   168,   170,   183,   184,   185,
  513.    186,   187,   188,   189,   249,   190,   191,   181,   196,   192,
  514.    197,   195,   198,   199,   200,   201,   202,   218,   216,   204,
  515.    203,   205,   206,   207,   208,   209,   211,     0,   212,   213,
  516.    215,   219,     0,   220,   221,   222,   223,   224,   225,   226,
  517.    227,   235,   228,   229,   232,   244,   233,   234,   236,     0,
  518.    241,   242,   240,   243,     0,   245,   246,   247
  519. };
  520.  
  521. static const short yycheck[] = {    91,
  522.     92,    93,    51,    16,    15,    97,    15,    81,    19,   101,
  523.    102,    15,   104,    62,    63,    64,    65,    66,    67,    68,
  524.     69,    70,    71,    72,    73,     4,     5,    15,    16,   121,
  525.     16,   123,   124,    15,    13,   127,   128,   129,    15,    16,
  526.      7,    16,    12,    13,    11,    12,    16,     0,     1,    19,
  527.     20,    21,    22,    15,    24,    15,    16,    27,    28,    29,
  528.     30,    31,   136,    33,    34,    15,    16,    20,    21,    15,
  529.     16,    24,    25,    26,    27,    28,    29,    30,    31,    32,
  530.      3,    15,    16,     6,    15,     8,     9,    40,    41,    42,
  531.     43,    44,    45,    46,    47,    48,    49,    50,    51,    52,
  532.     53,    54,    55,    56,    57,     5,    59,    60,    61,    15,
  533.     10,    15,    16,    15,    14,    16,    15,    16,    15,    16,
  534.     15,    16,    15,    15,    15,    19,    16,    16,    16,   197,
  535.     15,    18,    18,    15,    15,   227,    19,    15,   230,   109,
  536.    232,   111,   112,   113,   114,   115,   116,   117,    19,    18,
  537.     15,    15,    18,    15,    15,    18,    16,    16,    15,    15,
  538.     15,    19,    16,    16,    15,    17,    16,    15,    17,    16,
  539.     16,    16,    16,    16,    16,    16,    16,    16,    16,    16,
  540.     12,    16,    16,    16,     0,    16,    16,   135,    15,    18,
  541.     15,    19,    15,    15,    15,    15,    15,   198,   196,    16,
  542.     18,    16,    16,    16,    16,    16,    15,    -1,    16,    19,
  543.     16,    18,    -1,    18,    18,    18,    16,    19,    19,    16,
  544.     15,    17,    16,    16,    15,    17,    16,    16,    16,    -1,
  545.     16,    16,    19,    16,    -1,    19,    17,    19
  546. };
  547. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  548. #line 3 "/usr/lib/bison.simple"
  549.  
  550. /* Skeleton output parser for bison,
  551.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  552.  
  553.    This program is free software; you can redistribute it and/or modify
  554.    it under the terms of the GNU General Public License as published by
  555.    the Free Software Foundation; either version 1, or (at your option)
  556.    any later version.
  557.  
  558.    This program is distributed in the hope that it will be useful,
  559.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  560.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  561.    GNU General Public License for more details.
  562.  
  563.    You should have received a copy of the GNU General Public License
  564.    along with this program; if not, write to the Free Software
  565.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  566.  
  567.  
  568. #ifndef alloca
  569. #ifdef __GNUC__
  570. #define alloca __builtin_alloca
  571. #else /* not GNU C.  */
  572. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
  573. #include <alloca.h>
  574. #else /* not sparc */
  575. #if defined (MSDOS) && !defined (__TURBOC__)
  576. #include <malloc.h>
  577. #else /* not MSDOS, or __TURBOC__ */
  578. #if defined(_AIX)
  579. #include <malloc.h>
  580.  #pragma alloca
  581. #else /* not MSDOS, __TURBOC__, or _AIX */
  582. #ifdef __hpux
  583. #ifdef __cplusplus
  584. extern "C" {
  585. void *alloca (unsigned int);
  586. };
  587. #else /* not __cplusplus */
  588. void *alloca ();
  589. #endif /* not __cplusplus */
  590. #endif /* __hpux */
  591. #endif /* not _AIX */
  592. #endif /* not MSDOS, or __TURBOC__ */
  593. #endif /* not sparc.  */
  594. #endif /* not GNU C.  */
  595. #endif /* alloca not defined.  */
  596.  
  597. /* This is the parser code that is written into each bison parser
  598.   when the %semantic_parser declaration is not specified in the grammar.
  599.   It was written by Richard Stallman by simplifying the hairy parser
  600.   used when %semantic_parser is specified.  */
  601.  
  602. /* Note: there must be only one dollar sign in this file.
  603.    It is replaced by the list of actions, each action
  604.    as one case of the switch.  */
  605.  
  606. #define yyerrok        (yyerrstatus = 0)
  607. #define yyclearin    (yychar = YYEMPTY)
  608. #define YYEMPTY        -2
  609. #define YYEOF        0
  610. #define YYACCEPT    return(0)
  611. #define YYABORT     return(1)
  612. #define YYERROR        goto yyerrlab1
  613. /* Like YYERROR except do call yyerror.
  614.    This remains here temporarily to ease the
  615.    transition to the new meaning of YYERROR, for GCC.
  616.    Once GCC version 2 has supplanted version 1, this can go.  */
  617. #define YYFAIL        goto yyerrlab
  618. #define YYRECOVERING()  (!!yyerrstatus)
  619. #define YYBACKUP(token, value) \
  620. do                                \
  621.   if (yychar == YYEMPTY && yylen == 1)                \
  622.     { yychar = (token), yylval = (value);            \
  623.       yychar1 = YYTRANSLATE (yychar);                \
  624.       YYPOPSTACK;                        \
  625.       goto yybackup;                        \
  626.     }                                \
  627.   else                                \
  628.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  629. while (0)
  630.  
  631. #define YYTERROR    1
  632. #define YYERRCODE    256
  633.  
  634. #ifndef YYPURE
  635. #define YYLEX        yylex()
  636. #endif
  637.  
  638. #ifdef YYPURE
  639. #ifdef YYLSP_NEEDED
  640. #define YYLEX        yylex(&yylval, &yylloc)
  641. #else
  642. #define YYLEX        yylex(&yylval)
  643. #endif
  644. #endif
  645.  
  646. /* If nonreentrant, generate the variables here */
  647.  
  648. #ifndef YYPURE
  649.  
  650. int    yychar;            /*  the lookahead symbol        */
  651. YYSTYPE    yylval;            /*  the semantic value of the        */
  652.                 /*  lookahead symbol            */
  653.  
  654. #ifdef YYLSP_NEEDED
  655. YYLTYPE yylloc;            /*  location data for the lookahead    */
  656.                 /*  symbol                */
  657. #endif
  658.  
  659. int yynerrs;            /*  number of parse errors so far       */
  660. #endif  /* not YYPURE */
  661.  
  662. #if YYDEBUG != 0
  663. int yydebug;            /*  nonzero means print parse trace    */
  664. /* Since this is uninitialized, it does not stop multiple parsers
  665.    from coexisting.  */
  666. #endif
  667.  
  668. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  669.  
  670. #ifndef    YYINITDEPTH
  671. #define YYINITDEPTH 200
  672. #endif
  673.  
  674. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  675.     (effective only if the built-in stack extension method is used).  */
  676.  
  677. #if YYMAXDEPTH == 0
  678. #undef YYMAXDEPTH
  679. #endif
  680.  
  681. #ifndef YYMAXDEPTH
  682. #define YYMAXDEPTH 10000
  683. #endif
  684.  
  685. /* Prevent warning if -Wstrict-prototypes.  */
  686. #ifdef __GNUC__
  687. int yyparse (void);
  688. #endif
  689.  
  690. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  691. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  692. #else                /* not GNU C or C++ */
  693. #ifndef __cplusplus
  694.  
  695. /* This is the most reliable way to avoid incompatibilities
  696.    in available built-in functions on various systems.  */
  697. static void
  698. __yy_bcopy (from, to, count)
  699.      char *from;
  700.      char *to;
  701.      int count;
  702. {
  703.   register char *f = from;
  704.   register char *t = to;
  705.   register int i = count;
  706.  
  707.   while (i-- > 0)
  708.     *t++ = *f++;
  709. }
  710.  
  711. #else /* __cplusplus */
  712.  
  713. /* This is the most reliable way to avoid incompatibilities
  714.    in available built-in functions on various systems.  */
  715. static void
  716. __yy_bcopy (char *from, char *to, int count)
  717. {
  718.   register char *f = from;
  719.   register char *t = to;
  720.   register int i = count;
  721.  
  722.   while (i-- > 0)
  723.     *t++ = *f++;
  724. }
  725.  
  726. #endif
  727. #endif
  728.  
  729. #line 184 "/usr/lib/bison.simple"
  730. int
  731. yyparse()
  732. {
  733.   register int yystate;
  734.   register int yyn;
  735.   register short *yyssp;
  736.   register YYSTYPE *yyvsp;
  737.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  738.   int yychar1 = 0;        /*  lookahead token as an internal (translated) token number */
  739.  
  740.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  741.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  742.  
  743.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  744.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  745.  
  746. #ifdef YYLSP_NEEDED
  747.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  748.   YYLTYPE *yyls = yylsa;
  749.   YYLTYPE *yylsp;
  750.  
  751. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  752. #else
  753. #define YYPOPSTACK   (yyvsp--, yyssp--)
  754. #endif
  755.  
  756.   int yystacksize = YYINITDEPTH;
  757.  
  758. #ifdef YYPURE
  759.   int yychar;
  760.   YYSTYPE yylval;
  761.   int yynerrs;
  762. #ifdef YYLSP_NEEDED
  763.   YYLTYPE yylloc;
  764. #endif
  765. #endif
  766.  
  767.   YYSTYPE yyval;        /*  the variable used to return        */
  768.                 /*  semantic values from the action    */
  769.                 /*  routines                */
  770.  
  771.   int yylen;
  772.  
  773. #if YYDEBUG != 0
  774.   if (yydebug)
  775.     fprintf(stderr, "Starting parse\n");
  776. #endif
  777.  
  778.   yystate = 0;
  779.   yyerrstatus = 0;
  780.   yynerrs = 0;
  781.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  782.  
  783.   /* Initialize stack pointers.
  784.      Waste one element of value and location stack
  785.      so that they stay on the same level as the state stack.
  786.      The wasted elements are never initialized.  */
  787.  
  788.   yyssp = yyss - 1;
  789.   yyvsp = yyvs;
  790. #ifdef YYLSP_NEEDED
  791.   yylsp = yyls;
  792. #endif
  793.  
  794. /* Push a new state, which is found in  yystate  .  */
  795. /* In all cases, when you get here, the value and location stacks
  796.    have just been pushed. so pushing a state here evens the stacks.  */
  797. yynewstate:
  798.  
  799.   *++yyssp = yystate;
  800.  
  801.   if (yyssp >= yyss + yystacksize - 1)
  802.     {
  803.       /* Give user a chance to reallocate the stack */
  804.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  805.       YYSTYPE *yyvs1 = yyvs;
  806.       short *yyss1 = yyss;
  807. #ifdef YYLSP_NEEDED
  808.       YYLTYPE *yyls1 = yyls;
  809. #endif
  810.  
  811.       /* Get the current used size of the three stacks, in elements.  */
  812.       int size = yyssp - yyss + 1;
  813.  
  814. #ifdef yyoverflow
  815.       /* Each stack pointer address is followed by the size of
  816.      the data in use in that stack, in bytes.  */
  817. #ifdef YYLSP_NEEDED
  818.       /* This used to be a conditional around just the two extra args,
  819.      but that might be undefined if yyoverflow is a macro.  */
  820.       yyoverflow("parser stack overflow",
  821.          &yyss1, size * sizeof (*yyssp),
  822.          &yyvs1, size * sizeof (*yyvsp),
  823.          &yyls1, size * sizeof (*yylsp),
  824.          &yystacksize);
  825. #else
  826.       yyoverflow("parser stack overflow",
  827.          &yyss1, size * sizeof (*yyssp),
  828.          &yyvs1, size * sizeof (*yyvsp),
  829.          &yystacksize);
  830. #endif
  831.  
  832.       yyss = yyss1; yyvs = yyvs1;
  833. #ifdef YYLSP_NEEDED
  834.       yyls = yyls1;
  835. #endif
  836. #else /* no yyoverflow */
  837.       /* Extend the stack our own way.  */
  838.       if (yystacksize >= YYMAXDEPTH)
  839.     {
  840.       yyerror("parser stack overflow");
  841.       return 2;
  842.     }
  843.       yystacksize *= 2;
  844.       if (yystacksize > YYMAXDEPTH)
  845.     yystacksize = YYMAXDEPTH;
  846.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  847.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  848.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  849.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  850. #ifdef YYLSP_NEEDED
  851.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  852.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  853. #endif
  854. #endif /* no yyoverflow */
  855.  
  856.       yyssp = yyss + size - 1;
  857.       yyvsp = yyvs + size - 1;
  858. #ifdef YYLSP_NEEDED
  859.       yylsp = yyls + size - 1;
  860. #endif
  861.  
  862. #if YYDEBUG != 0
  863.       if (yydebug)
  864.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  865. #endif
  866.  
  867.       if (yyssp >= yyss + yystacksize - 1)
  868.     YYABORT;
  869.     }
  870.  
  871. #if YYDEBUG != 0
  872.   if (yydebug)
  873.     fprintf(stderr, "Entering state %d\n", yystate);
  874. #endif
  875.  
  876.   goto yybackup;
  877.  yybackup:
  878.  
  879. /* Do appropriate processing given the current state.  */
  880. /* Read a lookahead token if we need one and don't already have one.  */
  881. /* yyresume: */
  882.  
  883.   /* First try to decide what to do without reference to lookahead token.  */
  884.  
  885.   yyn = yypact[yystate];
  886.   if (yyn == YYFLAG)
  887.     goto yydefault;
  888.  
  889.   /* Not known => get a lookahead token if don't already have one.  */
  890.  
  891.   /* yychar is either YYEMPTY or YYEOF
  892.      or a valid token in external form.  */
  893.  
  894.   if (yychar == YYEMPTY)
  895.     {
  896. #if YYDEBUG != 0
  897.       if (yydebug)
  898.     fprintf(stderr, "Reading a token: ");
  899. #endif
  900.       yychar = YYLEX;
  901.     }
  902.  
  903.   /* Convert token to internal form (in yychar1) for indexing tables with */
  904.  
  905.   if (yychar <= 0)        /* This means end of input. */
  906.     {
  907.       yychar1 = 0;
  908.       yychar = YYEOF;        /* Don't call YYLEX any more */
  909.  
  910. #if YYDEBUG != 0
  911.       if (yydebug)
  912.     fprintf(stderr, "Now at end of input.\n");
  913. #endif
  914.     }
  915.   else
  916.     {
  917.       yychar1 = YYTRANSLATE(yychar);
  918.  
  919. #if YYDEBUG != 0
  920.       if (yydebug)
  921.     {
  922.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  923.       /* Give the individual parser a way to print the precise meaning
  924.          of a token, for further debugging info.  */
  925. #ifdef YYPRINT
  926.       YYPRINT (stderr, yychar, yylval);
  927. #endif
  928.       fprintf (stderr, ")\n");
  929.     }
  930. #endif
  931.     }
  932.  
  933.   yyn += yychar1;
  934.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  935.     goto yydefault;
  936.  
  937.   yyn = yytable[yyn];
  938.  
  939.   /* yyn is what to do for this token type in this state.
  940.      Negative => reduce, -yyn is rule number.
  941.      Positive => shift, yyn is new state.
  942.        New state is final state => don't bother to shift,
  943.        just return success.
  944.      0, or most negative number => error.  */
  945.  
  946.   if (yyn < 0)
  947.     {
  948.       if (yyn == YYFLAG)
  949.     goto yyerrlab;
  950.       yyn = -yyn;
  951.       goto yyreduce;
  952.     }
  953.   else if (yyn == 0)
  954.     goto yyerrlab;
  955.  
  956.   if (yyn == YYFINAL)
  957.     YYACCEPT;
  958.  
  959.   /* Shift the lookahead token.  */
  960.  
  961. #if YYDEBUG != 0
  962.   if (yydebug)
  963.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  964. #endif
  965.  
  966.   /* Discard the token being shifted unless it is eof.  */
  967.   if (yychar != YYEOF)
  968.     yychar = YYEMPTY;
  969.  
  970.   *++yyvsp = yylval;
  971. #ifdef YYLSP_NEEDED
  972.   *++yylsp = yylloc;
  973. #endif
  974.  
  975.   /* count tokens shifted since error; after three, turn off error status.  */
  976.   if (yyerrstatus) yyerrstatus--;
  977.  
  978.   yystate = yyn;
  979.   goto yynewstate;
  980.  
  981. /* Do the default action for the current state.  */
  982. yydefault:
  983.  
  984.   yyn = yydefact[yystate];
  985.   if (yyn == 0)
  986.     goto yyerrlab;
  987.  
  988. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  989. yyreduce:
  990.   yylen = yyr2[yyn];
  991.   if (yylen > 0)
  992.     yyval = yyvsp[1-yylen]; /* implement default value of the action */
  993.  
  994. #if YYDEBUG != 0
  995.   if (yydebug)
  996.     {
  997.       int i;
  998.  
  999.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  1000.            yyn, yyrline[yyn]);
  1001.  
  1002.       /* Print the symbols being reduced, and their result.  */
  1003.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  1004.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  1005.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  1006.     }
  1007. #endif
  1008.  
  1009.  
  1010.   switch (yyn) {
  1011.  
  1012. case 2:
  1013. #line 238 "ftpcmd.y"
  1014. {
  1015.             fromname = 0;
  1016.             restart_point = 0;
  1017.         ;
  1018.     break;}
  1019. case 4:
  1020. #line 246 "ftpcmd.y"
  1021. {
  1022.             user(yyvsp[-1].String);
  1023.             if (log_commands) syslog(LOG_INFO, "USER %s", yyvsp[-1].String);
  1024.             free(yyvsp[-1].String);
  1025.         ;
  1026.     break;}
  1027. case 5:
  1028. #line 252 "ftpcmd.y"
  1029. {
  1030.             if (log_commands)
  1031.                 if (anonymous)
  1032.                     syslog(LOG_INFO, "PASS %s", yyvsp[-1].String);
  1033.                 else
  1034.                     syslog(LOG_INFO, "PASS password");
  1035.  
  1036.             pass(yyvsp[-1].String);
  1037.             free(yyvsp[-1].String);
  1038.         ;
  1039.     break;}
  1040. case 6:
  1041. #line 263 "ftpcmd.y"
  1042. {
  1043.             if (log_commands) syslog(LOG_INFO, "PORT");
  1044.             usedefault = 0;
  1045.             if (pdata >= 0) {
  1046.                 (void) close(pdata);
  1047.                 pdata = -1;
  1048.             }
  1049.             reply(200, "PORT command successful.");
  1050.         ;
  1051.     break;}
  1052. case 7:
  1053. #line 273 "ftpcmd.y"
  1054. {
  1055.             if (log_commands) syslog(LOG_INFO, "PASV");
  1056.             passive();
  1057.         ;
  1058.     break;}
  1059. case 8:
  1060. #line 278 "ftpcmd.y"
  1061. {
  1062.             if (log_commands) syslog(LOG_INFO, "TYPE %s", typenames[cmd_type]);
  1063.             switch (cmd_type) {
  1064.  
  1065.             case TYPE_A:
  1066.                 if (cmd_form == FORM_N) {
  1067.                     reply(200, "Type set to A.");
  1068.                     type = cmd_type;
  1069.                     form = cmd_form;
  1070.                 } else
  1071.                     reply(504, "Form must be N.");
  1072.                 break;
  1073.  
  1074.             case TYPE_E:
  1075.                 reply(504, "Type E not implemented.");
  1076.                 break;
  1077.  
  1078.             case TYPE_I:
  1079.                 reply(200, "Type set to I.");
  1080.                 type = cmd_type;
  1081.                 break;
  1082.  
  1083.             case TYPE_L:
  1084. #if NBBY == 8
  1085.                 if (cmd_bytesz == 8) {
  1086.                     reply(200,
  1087.                         "Type set to L (byte size 8).");
  1088.                     type = cmd_type;
  1089.                 } else
  1090.                     reply(504, "Byte size must be 8.");
  1091. #else /* NBBY == 8 */
  1092.                 UNIMPLEMENTED for NBBY != 8
  1093. #endif /* NBBY == 8 */
  1094.             }
  1095.         ;
  1096.     break;}
  1097. case 9:
  1098. #line 314 "ftpcmd.y"
  1099. {
  1100.             if (log_commands) syslog(LOG_INFO, "STRU %s", strunames[yyvsp[-1].Number]);
  1101.             switch (yyvsp[-1].Number) {
  1102.  
  1103.             case STRU_F:
  1104.                 reply(200, "STRU F ok.");
  1105.                 break;
  1106.  
  1107.             default:
  1108.                 reply(504, "Unimplemented STRU type.");
  1109.             }
  1110.         ;
  1111.     break;}
  1112. case 10:
  1113. #line 327 "ftpcmd.y"
  1114. {
  1115.             if (log_commands) syslog(LOG_INFO, "MODE %s", modenames[yyvsp[-1].Number]);
  1116.             switch (yyvsp[-1].Number) {
  1117.  
  1118.             case MODE_S:
  1119.                 reply(200, "MODE S ok.");
  1120.                 break;
  1121.  
  1122.             default:
  1123.                 reply(502, "Unimplemented MODE type.");
  1124.             }
  1125.         ;
  1126.     break;}
  1127. case 11:
  1128. #line 340 "ftpcmd.y"
  1129. {
  1130.             if (log_commands) syslog(LOG_INFO, "ALLO %d", yyvsp[-1].Number);
  1131.             reply(202, "ALLO command ignored.");
  1132.         ;
  1133.     break;}
  1134. case 12:
  1135. #line 345 "ftpcmd.y"
  1136. {
  1137.             if (log_commands) syslog(LOG_INFO, "ALLO %d R %d", yyvsp[-5].Number, yyvsp[-1].Number);
  1138.             reply(202, "ALLO command ignored.");
  1139.         ;
  1140.     break;}
  1141. case 13:
  1142. #line 350 "ftpcmd.y"
  1143. {
  1144.             if (log_commands) syslog(LOG_INFO, "RETR %s", yyvsp[-1].String);
  1145.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1146.                 retrieve((char *) NULL, yyvsp[-1].String);
  1147.             if (yyvsp[-1].String != NULL)
  1148.                 free(yyvsp[-1].String);
  1149.         ;
  1150.     break;}
  1151. case 14:
  1152. #line 358 "ftpcmd.y"
  1153. {
  1154.             if (log_commands) syslog(LOG_INFO, "STOR %s", yyvsp[-1].String);
  1155.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1156.                 store(yyvsp[-1].String, "w", 0);
  1157.             if (yyvsp[-1].String != NULL)
  1158.                 free(yyvsp[-1].String);
  1159.         ;
  1160.     break;}
  1161. case 15:
  1162. #line 366 "ftpcmd.y"
  1163. {
  1164.             if (log_commands) syslog(LOG_INFO, "APPE %s", yyvsp[-1].String);
  1165.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1166.                 store(yyvsp[-1].String, "a", 0);
  1167.             if (yyvsp[-1].String != NULL)
  1168.                 free(yyvsp[-1].String);
  1169.         ;
  1170.     break;}
  1171. case 16:
  1172. #line 374 "ftpcmd.y"
  1173. {
  1174.             if (log_commands) syslog(LOG_INFO, "NLST");
  1175.             if (yyvsp[-1].Number)
  1176.                 send_file_list(".");
  1177.         ;
  1178.     break;}
  1179. case 17:
  1180. #line 380 "ftpcmd.y"
  1181. {
  1182.             if (log_commands) syslog(LOG_INFO, "NLST %s", yyvsp[-1].String);
  1183.             if (yyvsp[-3].Number && yyvsp[-1].String) {
  1184.                 send_file_list(yyvsp[-1].String);
  1185.                 free(yyvsp[-1].String);
  1186.             }
  1187.         ;
  1188.     break;}
  1189. case 18:
  1190. #line 388 "ftpcmd.y"
  1191. {
  1192.             if (log_commands) syslog(LOG_INFO, "LIST");
  1193.             if (yyvsp[-1].Number)
  1194.         if (anonymous && dolreplies)
  1195.                 retrieve(ls_long, "");
  1196.             else
  1197.                 retrieve(ls_short, "");
  1198.         ;
  1199.     break;}
  1200. case 19:
  1201. #line 397 "ftpcmd.y"
  1202. {
  1203.             if (log_commands) syslog(LOG_INFO, "LIST %s", yyvsp[-1].String);
  1204.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1205.         if (anonymous && dolreplies)
  1206.                 retrieve(ls_long, yyvsp[-1].String);
  1207.             else
  1208.                 retrieve(ls_short, yyvsp[-1].String);
  1209.             if (yyvsp[-1].String != NULL)
  1210.                 free(yyvsp[-1].String);
  1211.         ;
  1212.     break;}
  1213. case 20:
  1214. #line 408 "ftpcmd.y"
  1215. {
  1216.             if (log_commands) syslog(LOG_INFO, "STAT %s", yyvsp[-1].String);
  1217.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1218.                 statfilecmd(yyvsp[-1].String);
  1219.             if (yyvsp[-1].String != NULL)
  1220.                 free(yyvsp[-1].String);
  1221.         ;
  1222.     break;}
  1223. case 21:
  1224. #line 416 "ftpcmd.y"
  1225. {
  1226.             if (log_commands) syslog(LOG_INFO, "STAT");
  1227.             statcmd();
  1228.         ;
  1229.     break;}
  1230. case 22:
  1231. #line 421 "ftpcmd.y"
  1232. {
  1233.             if (log_commands) syslog(LOG_INFO, "DELE %s", yyvsp[-1].String);
  1234.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1235.                 delete(yyvsp[-1].String);
  1236.             if (yyvsp[-1].String != NULL)
  1237.                 free(yyvsp[-1].String);
  1238.         ;
  1239.     break;}
  1240. case 23:
  1241. #line 429 "ftpcmd.y"
  1242. {
  1243.             if (log_commands) syslog(LOG_INFO, "RNTO %s", yyvsp[-1].String);
  1244.             if (fromname) {
  1245.                 renamecmd(fromname, yyvsp[-1].String);
  1246.                 free(fromname);
  1247.                 fromname = (char *) NULL;
  1248.             } else {
  1249.                 reply(503, "Bad sequence of commands.");
  1250.             }
  1251.             free(yyvsp[-1].String);
  1252.         ;
  1253.     break;}
  1254. case 24:
  1255. #line 441 "ftpcmd.y"
  1256. {
  1257.             if (log_commands) syslog(LOG_INFO, "ABOR");
  1258.             reply(225, "ABOR command successful.");
  1259.         ;
  1260.     break;}
  1261. case 25:
  1262. #line 446 "ftpcmd.y"
  1263. {
  1264.             if (log_commands) syslog(LOG_INFO, "CWD");
  1265.             if (yyvsp[-1].Number)
  1266.                 cwd(pw->pw_dir);
  1267.         ;
  1268.     break;}
  1269. case 26:
  1270. #line 452 "ftpcmd.y"
  1271. {
  1272.             if (log_commands) syslog(LOG_INFO, "CWD %s", yyvsp[-1].String);
  1273.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1274.                 cwd(yyvsp[-1].String);
  1275.             if (yyvsp[-1].String != NULL)
  1276.                 free(yyvsp[-1].String);
  1277.         ;
  1278.     break;}
  1279. case 27:
  1280. #line 460 "ftpcmd.y"
  1281. {
  1282.             if (log_commands) syslog(LOG_INFO, "HELP");
  1283.             help(cmdtab, (char *) NULL);
  1284.         ;
  1285.     break;}
  1286. case 28:
  1287. #line 465 "ftpcmd.y"
  1288. {
  1289.             register char *cp = (char *)yyvsp[-1].String;
  1290.  
  1291.             if (log_commands) syslog(LOG_INFO, "HELP %s", yyvsp[-1].String);
  1292.             if (strncasecmp(cp, "SITE", 4) == 0) {
  1293.                 cp = (char *)yyvsp[-1].String + 4;
  1294.                 if (*cp == ' ')
  1295.                     cp++;
  1296.                 if (*cp)
  1297.                     help(sitetab, cp);
  1298.                 else
  1299.                     help(sitetab, (char *) NULL);
  1300.             } else
  1301.                 help(cmdtab, yyvsp[-1].String);
  1302.         ;
  1303.     break;}
  1304. case 29:
  1305. #line 481 "ftpcmd.y"
  1306. {
  1307.             if (log_commands) syslog(LOG_INFO, "NOOP");
  1308.             reply(200, "NOOP command successful.");
  1309.         ;
  1310.     break;}
  1311. case 30:
  1312. #line 486 "ftpcmd.y"
  1313. {
  1314.             if (log_commands) syslog(LOG_INFO, "MKD %s", yyvsp[-1].String);
  1315.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1316.                 makedir(yyvsp[-1].String);
  1317.             if (yyvsp[-1].String != NULL)
  1318.                 free(yyvsp[-1].String);
  1319.         ;
  1320.     break;}
  1321. case 31:
  1322. #line 494 "ftpcmd.y"
  1323. {
  1324.             if (log_commands) syslog(LOG_INFO, "RMD %s", yyvsp[-1].String);
  1325.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1326.                 removedir(yyvsp[-1].String);
  1327.             if (yyvsp[-1].String != NULL)
  1328.                 free(yyvsp[-1].String);
  1329.         ;
  1330.     break;}
  1331. case 32:
  1332. #line 502 "ftpcmd.y"
  1333. {
  1334.             if (log_commands) syslog(LOG_INFO, "PWD");
  1335.             if (yyvsp[-1].Number)
  1336.                 pwd();
  1337.         ;
  1338.     break;}
  1339. case 33:
  1340. #line 508 "ftpcmd.y"
  1341. {
  1342.             if (log_commands) syslog(LOG_INFO, "CDUP");
  1343.             if (yyvsp[-1].Number)
  1344.                 cwd("..");
  1345.         ;
  1346.     break;}
  1347. case 34:
  1348. #line 514 "ftpcmd.y"
  1349. {
  1350.             if (log_commands) syslog(LOG_INFO, "SITE HELP");
  1351.             help(sitetab, (char *) NULL);
  1352.         ;
  1353.     break;}
  1354. case 35:
  1355. #line 519 "ftpcmd.y"
  1356. {
  1357.             if (log_commands) syslog(LOG_INFO, "SITE HELP %s", yyvsp[-1].String);
  1358.             help(sitetab, yyvsp[-1].String);
  1359.         ;
  1360.     break;}
  1361. case 36:
  1362. #line 524 "ftpcmd.y"
  1363. {
  1364.             mode_t oldmask;
  1365.  
  1366.             if (log_commands) syslog(LOG_INFO, "SITE UMASK");
  1367.             if (yyvsp[-1].Number) {
  1368.                 oldmask = umask(0);
  1369.                 (void) umask(oldmask);
  1370.                 reply(200, "Current UMASK is %03o", oldmask);
  1371.             }
  1372.         ;
  1373.     break;}
  1374. case 37:
  1375. #line 535 "ftpcmd.y"
  1376. {
  1377.             mode_t oldmask;
  1378.             struct aclmember *entry = NULL;
  1379.             int ok = 1;
  1380.  
  1381.             if (log_commands) syslog(LOG_INFO, "SITE UMASK %d", yyvsp[-1].Number);
  1382.             if (yyvsp[-3].Number) {
  1383.                 /* check for umask permission */
  1384.                 while (getaclentry("umask", &entry) && ARG0 && ARG1 != NULL) {
  1385.                     if (type_match(ARG1)) 
  1386.                         if (*ARG0 == 'n')  ok = 0;
  1387.                 }
  1388.                 if (ok) {
  1389.                     if ((yyvsp[-1].Number == -1) || (yyvsp[-1].Number > 0777)) {
  1390.                         reply(501, "Bad UMASK value");
  1391.                     } else {
  1392.                         oldmask = umask((mode_t)yyvsp[-1].Number);
  1393.                         reply(200, "UMASK set to %03o (was %03o)", yyvsp[-1].Number, oldmask);
  1394.                     }
  1395.                 } else 
  1396.                     reply(553, "Permission denied. (umask)");
  1397.             }
  1398.         ;
  1399.     break;}
  1400. case 38:
  1401. #line 559 "ftpcmd.y"
  1402. {
  1403.             struct aclmember *entry = NULL;
  1404.             int ok = 1;
  1405.  
  1406.             if (log_commands) syslog(LOG_INFO, "SITE CHMOD %d %s", yyvsp[-3].Number, yyvsp[-1].String);
  1407.             if (yyvsp[-5].Number && yyvsp[-3].Number && yyvsp[-1].String) {
  1408.                 /* check for chmod permission */
  1409.                 while (getaclentry("chmod", &entry) && ARG0 && ARG1 != NULL) {
  1410.                     if (type_match(ARG1)) 
  1411.                         if (*ARG0 == 'n')  ok = 0;
  1412.                 }
  1413.                 if (ok) {
  1414.                     if (yyvsp[-3].Number > 0777)
  1415.                         reply(501, 
  1416.                             "CHMOD: Mode value must be between 0 and 0777");
  1417.                     else if (chmod(yyvsp[-1].String, (mode_t) yyvsp[-3].Number) < 0)
  1418.                         perror_reply(550, yyvsp[-1].String);
  1419.                     else
  1420.                         reply(200, "CHMOD command successful.");
  1421.                     free(yyvsp[-1].String);
  1422.                 } else
  1423.                     reply(553, "Permission denied. (chmod)");
  1424.             }
  1425.         ;
  1426.     break;}
  1427. case 39:
  1428. #line 584 "ftpcmd.y"
  1429. {
  1430.             if (log_commands) syslog(LOG_INFO, "SITE IDLE");
  1431.             reply(200,
  1432.                 "Current IDLE time limit is %d seconds; max %d",
  1433.                 timeout, maxtimeout);
  1434.         ;
  1435.     break;}
  1436. case 40:
  1437. #line 591 "ftpcmd.y"
  1438. {
  1439.             if (log_commands) syslog(LOG_INFO, "SITE IDLE %d", yyvsp[-1].Number);
  1440.             if (yyvsp[-1].Number < 30 || yyvsp[-1].Number > maxtimeout) {
  1441.                 reply(501,
  1442.             "Maximum IDLE time must be between 30 and %d seconds",
  1443.                     maxtimeout);
  1444.             } else {
  1445.                 timeout = yyvsp[-1].Number;
  1446.                 (void) alarm((unsigned) timeout);
  1447.                 reply(200, "Maximum IDLE time set to %d seconds", timeout);
  1448.             }
  1449.         ;
  1450.     break;}
  1451. case 41:
  1452. #line 604 "ftpcmd.y"
  1453. {
  1454. #ifndef NO_PRIVATE
  1455.             if (log_commands) syslog(LOG_INFO, "SITE GROUP %s", yyvsp[-1].String);
  1456.             if (yyvsp[-3].Number && yyvsp[-1].String) priv_group(yyvsp[-1].String);
  1457.             free(yyvsp[-1].String);
  1458. #endif /* !NO_PRIVATE */
  1459.         ;
  1460.     break;}
  1461. case 42:
  1462. #line 612 "ftpcmd.y"
  1463. {
  1464. #ifndef NO_PRIVATE
  1465.             if (log_commands) syslog(LOG_INFO, "SITE GPASS password");
  1466.             if (yyvsp[-3].Number && yyvsp[-1].String) priv_gpass(yyvsp[-1].String);
  1467.             free(yyvsp[-1].String);
  1468. #endif /* !NO_PRIVATE */
  1469.         ;
  1470.     break;}
  1471. case 43:
  1472. #line 620 "ftpcmd.y"
  1473. {
  1474.             if (yyvsp[-3].Number && yyvsp[-1].String) newer(yyvsp[-1].String, ".", 0);
  1475.             free(yyvsp[-1].String);
  1476.         ;
  1477.     break;}
  1478. case 44:
  1479. #line 625 "ftpcmd.y"
  1480. {
  1481.             if (yyvsp[-5].Number && yyvsp[-3].String && yyvsp[-1].String) newer(yyvsp[-3].String, yyvsp[-1].String, 0);
  1482.             free(yyvsp[-3].String);
  1483.             free(yyvsp[-1].String);
  1484.         ;
  1485.     break;}
  1486. case 45:
  1487. #line 631 "ftpcmd.y"
  1488. {
  1489.             if (yyvsp[-5].Number && yyvsp[-3].String && yyvsp[-1].String) newer(yyvsp[-3].String, yyvsp[-1].String, 1);
  1490.             free(yyvsp[-3].String);
  1491.             free(yyvsp[-1].String);
  1492.         ;
  1493.     break;}
  1494. case 46:
  1495. #line 637 "ftpcmd.y"
  1496. {
  1497.             /* this is just for backward compatibility since we
  1498.              * thought of INDEX before we thought of EXEC
  1499.              */
  1500.             if (yyvsp[-3].Number != 0 && yyvsp[-1].String != NULL) {
  1501.                 char buf[MAXPATHLEN];
  1502.                 if (strlen(yyvsp[-1].String) + 7 <= sizeof(buf)) {
  1503.                     sprintf(buf, "index %s", (char*)yyvsp[-1].String);
  1504.                     (void) site_exec(buf);
  1505.                 }
  1506.             }
  1507.         ;
  1508.     break;}
  1509. case 47:
  1510. #line 650 "ftpcmd.y"
  1511. {
  1512.             if (yyvsp[-3].Number != 0 && yyvsp[-1].String != NULL) {
  1513.                 (void) site_exec((char*)yyvsp[-1].String);
  1514.             }
  1515.         ;
  1516.     break;}
  1517. case 48:
  1518. #line 656 "ftpcmd.y"
  1519. {
  1520.             if (log_commands) syslog(LOG_INFO, "STOU %s", yyvsp[-1].String);
  1521.             if (yyvsp[-3].Number && yyvsp[-1].String) {
  1522.                 store(yyvsp[-1].String, "w", 1);
  1523.                 free(yyvsp[-1].String);
  1524.             }
  1525.         ;
  1526.     break;}
  1527. case 49:
  1528. #line 664 "ftpcmd.y"
  1529. {
  1530.             if (log_commands) syslog(LOG_INFO, "SYST");
  1531. #ifdef unix
  1532. #ifdef BSD
  1533.             reply(215, "UNIX Type: L%d Version: BSD-%d",
  1534.                 NBBY, BSD);
  1535. #else  /* BSD */
  1536.             reply(215, "UNIX Type: L%d", NBBY);
  1537. #endif /* BSD */
  1538. #else  /* unix */
  1539.             reply(215, "UNKNOWN Type: L%d", NBBY);
  1540. #endif /* unix */
  1541.         ;
  1542.     break;}
  1543. case 50:
  1544. #line 686 "ftpcmd.y"
  1545. {
  1546.             if (log_commands) syslog(LOG_INFO, "SIZE %s", yyvsp[-1].String);
  1547.             if (yyvsp[-3].Number && yyvsp[-1].String) {
  1548.                 sizecmd(yyvsp[-1].String);
  1549.                 free(yyvsp[-1].String);
  1550.             }
  1551.         ;
  1552.     break;}
  1553. case 51:
  1554. #line 704 "ftpcmd.y"
  1555. {
  1556.             if (log_commands) syslog(LOG_INFO, "MDTM %s", yyvsp[-1].String);
  1557.             if (yyvsp[-3].Number && yyvsp[-1].String) {
  1558.                 struct stat stbuf;
  1559.  
  1560.                 if (stat(yyvsp[-1].String, &stbuf) < 0)
  1561.                     perror_reply(550, yyvsp[-1].String);
  1562.                 else if ((stbuf.st_mode&S_IFMT) != S_IFREG) {
  1563.                     reply(550, "%s: not a plain file.",
  1564.                         yyvsp[-1].String);
  1565.                 } else {
  1566.                     register struct tm *t;
  1567.                     struct tm *gmtime();
  1568.                     t = gmtime(&stbuf.st_mtime);
  1569.                     reply(213,
  1570.                         "19%02d%02d%02d%02d%02d%02d",
  1571.                         t->tm_year, t->tm_mon+1, t->tm_mday,
  1572.                         t->tm_hour, t->tm_min, t->tm_sec);
  1573.                 }
  1574.                 free(yyvsp[-1].String);
  1575.             }
  1576.         ;
  1577.     break;}
  1578. case 52:
  1579. #line 727 "ftpcmd.y"
  1580. {
  1581.             if (log_commands) syslog(LOG_INFO, "QUIT");
  1582.             reply(221, "Goodbye.");
  1583.             dologout(0);
  1584.         ;
  1585.     break;}
  1586. case 53:
  1587. #line 733 "ftpcmd.y"
  1588. {
  1589.             yyerrok;
  1590.         ;
  1591.     break;}
  1592. case 54:
  1593. #line 738 "ftpcmd.y"
  1594. {
  1595.             char *renamefrom();
  1596.  
  1597.             if (log_commands) syslog(LOG_INFO, "RNFR %s", yyvsp[-1].String);
  1598.             restart_point = (off_t) 0;
  1599.             if (yyvsp[-3].Number && yyvsp[-1].String) {
  1600.                 fromname = renamefrom(yyvsp[-1].String);
  1601.                 if (fromname == 0 && yyvsp[-1].String) {
  1602.                     free(yyvsp[-1].String);
  1603.                 }
  1604.             }
  1605.         ;
  1606.     break;}
  1607. case 55:
  1608. #line 751 "ftpcmd.y"
  1609. {
  1610.             long atol();
  1611.  
  1612.             fromname = 0;
  1613.             restart_point = yyvsp[-1].Number;
  1614.             if (log_commands) syslog(LOG_INFO, "REST %d", restart_point);
  1615.             reply(350, "Restarting at %ld. %s", restart_point,
  1616.                 "Send STORE or RETRIEVE to initiate transfer.");
  1617.         ;
  1618.     break;}
  1619. case 56:
  1620. #line 762 "ftpcmd.y"
  1621. {
  1622.            if (log_commands) syslog(LOG_INFO, "SITE ALIAS");
  1623.            alias ((char *)NULL);
  1624.         ;
  1625.     break;}
  1626. case 57:
  1627. #line 767 "ftpcmd.y"
  1628. {
  1629.            if (log_commands) syslog(LOG_INFO, "SITE ALIAS %s", yyvsp[-1].String);
  1630.            alias (yyvsp[-1].String);
  1631.         ;
  1632.     break;}
  1633. case 58:
  1634. #line 772 "ftpcmd.y"
  1635. {
  1636.            if (log_commands) syslog(LOG_INFO, "SITE GROUPS");
  1637.            print_groups () ;
  1638.         ;
  1639.     break;}
  1640. case 59:
  1641. #line 777 "ftpcmd.y"
  1642. {
  1643.            if (log_commands) syslog(LOG_INFO, "SITE CDPATH");
  1644.            cdpath () ;
  1645.         ;
  1646.     break;}
  1647. case 61:
  1648. #line 787 "ftpcmd.y"
  1649. {
  1650.             yyval.String = (char *) malloc(1);
  1651.             yyval.String[0] = '\0';
  1652.         ;
  1653.     break;}
  1654. case 64:
  1655. #line 799 "ftpcmd.y"
  1656. {
  1657.             register char *a, *p;
  1658.  
  1659.             a = (char *)&data_dest.sin_addr;
  1660.             a[0] = yyvsp[-10].Number; a[1] = yyvsp[-8].Number; a[2] = yyvsp[-6].Number; a[3] = yyvsp[-4].Number;
  1661.             p = (char *)&data_dest.sin_port;
  1662.             p[0] = yyvsp[-2].Number; p[1] = yyvsp[0].Number;
  1663.             data_dest.sin_family = AF_INET;
  1664.         ;
  1665.     break;}
  1666. case 65:
  1667. #line 811 "ftpcmd.y"
  1668. {
  1669.         yyval.Number = FORM_N;
  1670.     ;
  1671.     break;}
  1672. case 66:
  1673. #line 815 "ftpcmd.y"
  1674. {
  1675.         yyval.Number = FORM_T;
  1676.     ;
  1677.     break;}
  1678. case 67:
  1679. #line 819 "ftpcmd.y"
  1680. {
  1681.         yyval.Number = FORM_C;
  1682.     ;
  1683.     break;}
  1684. case 68:
  1685. #line 825 "ftpcmd.y"
  1686. {
  1687.         cmd_type = TYPE_A;
  1688.         cmd_form = FORM_N;
  1689.     ;
  1690.     break;}
  1691. case 69:
  1692. #line 830 "ftpcmd.y"
  1693. {
  1694.         cmd_type = TYPE_A;
  1695.         cmd_form = yyvsp[0].Number;
  1696.     ;
  1697.     break;}
  1698. case 70:
  1699. #line 835 "ftpcmd.y"
  1700. {
  1701.         cmd_type = TYPE_E;
  1702.         cmd_form = FORM_N;
  1703.     ;
  1704.     break;}
  1705. case 71:
  1706. #line 840 "ftpcmd.y"
  1707. {
  1708.         cmd_type = TYPE_E;
  1709.         cmd_form = yyvsp[0].Number;
  1710.     ;
  1711.     break;}
  1712. case 72:
  1713. #line 845 "ftpcmd.y"
  1714. {
  1715.         cmd_type = TYPE_I;
  1716.     ;
  1717.     break;}
  1718. case 73:
  1719. #line 849 "ftpcmd.y"
  1720. {
  1721.         cmd_type = TYPE_L;
  1722.         cmd_bytesz = NBBY;
  1723.     ;
  1724.     break;}
  1725. case 74:
  1726. #line 854 "ftpcmd.y"
  1727. {
  1728.         cmd_type = TYPE_L;
  1729.         cmd_bytesz = yyvsp[0].Number;
  1730.     ;
  1731.     break;}
  1732. case 75:
  1733. #line 860 "ftpcmd.y"
  1734. {
  1735.         cmd_type = TYPE_L;
  1736.         cmd_bytesz = yyvsp[0].Number;
  1737.     ;
  1738.     break;}
  1739. case 76:
  1740. #line 867 "ftpcmd.y"
  1741. {
  1742.         yyval.Number = STRU_F;
  1743.     ;
  1744.     break;}
  1745. case 77:
  1746. #line 871 "ftpcmd.y"
  1747. {
  1748.         yyval.Number = STRU_R;
  1749.     ;
  1750.     break;}
  1751. case 78:
  1752. #line 875 "ftpcmd.y"
  1753. {
  1754.         yyval.Number = STRU_P;
  1755.     ;
  1756.     break;}
  1757. case 79:
  1758. #line 881 "ftpcmd.y"
  1759. {
  1760.         yyval.Number = MODE_S;
  1761.     ;
  1762.     break;}
  1763. case 80:
  1764. #line 885 "ftpcmd.y"
  1765. {
  1766.         yyval.Number = MODE_B;
  1767.     ;
  1768.     break;}
  1769. case 81:
  1770. #line 889 "ftpcmd.y"
  1771. {
  1772.         yyval.Number = MODE_C;
  1773.     ;
  1774.     break;}
  1775. case 82:
  1776. #line 895 "ftpcmd.y"
  1777. {
  1778.         /*
  1779.          * Problem: this production is used for all pathname
  1780.          * processing, but only gives a 550 error reply.
  1781.          * This is a valid reply in some cases but not in others.
  1782.          */
  1783.         if (logged_in && yyvsp[0].String && strncmp(yyvsp[0].String, "~", 1) == 0) {
  1784.             yyval.String = *ftpglob(yyvsp[0].String);
  1785.             if (globerr) {
  1786.                 reply(550, globerr);
  1787.                 yyval.String = NULL;
  1788.             }
  1789.             free(yyvsp[0].String);
  1790.         } else
  1791.             yyval.String = yyvsp[0].String;
  1792.     ;
  1793.     break;}
  1794. case 84:
  1795. #line 917 "ftpcmd.y"
  1796. {
  1797.         register int ret, dec, multby, digit;
  1798.  
  1799.         /*
  1800.          * Convert a number that was read as decimal number
  1801.          * to what it would be if it had been read as octal.
  1802.          */
  1803.         dec = yyvsp[0].Number;
  1804.         multby = 1;
  1805.         ret = 0;
  1806.         while (dec) {
  1807.             digit = dec%10;
  1808.             if (digit > 7) {
  1809.                 ret = -1;
  1810.                 break;
  1811.             }
  1812.             ret += digit * multby;
  1813.             multby *= 8;
  1814.             dec /= 10;
  1815.         }
  1816.         yyval.Number = ret;
  1817.     ;
  1818.     break;}
  1819. case 85:
  1820. #line 942 "ftpcmd.y"
  1821. {
  1822.         if (logged_in)
  1823.             yyval.Number = 1;
  1824.         else {
  1825.             if (log_commands) syslog(LOG_INFO, "cmd failure - not logged in");
  1826.             reply(530, "Please login with USER and PASS.");
  1827.             yyval.Number = 0;
  1828.         }
  1829.     ;
  1830.     break;}
  1831. }
  1832.    /* the action file gets copied in in place of this dollarsign */
  1833. #line 465 "/usr/lib/bison.simple"
  1834.  
  1835.   yyvsp -= yylen;
  1836.   yyssp -= yylen;
  1837. #ifdef YYLSP_NEEDED
  1838.   yylsp -= yylen;
  1839. #endif
  1840.  
  1841. #if YYDEBUG != 0
  1842.   if (yydebug)
  1843.     {
  1844.       short *ssp1 = yyss - 1;
  1845.       fprintf (stderr, "state stack now");
  1846.       while (ssp1 != yyssp)
  1847.     fprintf (stderr, " %d", *++ssp1);
  1848.       fprintf (stderr, "\n");
  1849.     }
  1850. #endif
  1851.  
  1852.   *++yyvsp = yyval;
  1853.  
  1854. #ifdef YYLSP_NEEDED
  1855.   yylsp++;
  1856.   if (yylen == 0)
  1857.     {
  1858.       yylsp->first_line = yylloc.first_line;
  1859.       yylsp->first_column = yylloc.first_column;
  1860.       yylsp->last_line = (yylsp-1)->last_line;
  1861.       yylsp->last_column = (yylsp-1)->last_column;
  1862.       yylsp->text = 0;
  1863.     }
  1864.   else
  1865.     {
  1866.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1867.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1868.     }
  1869. #endif
  1870.  
  1871.   /* Now "shift" the result of the reduction.
  1872.      Determine what state that goes to,
  1873.      based on the state we popped back to
  1874.      and the rule number reduced by.  */
  1875.  
  1876.   yyn = yyr1[yyn];
  1877.  
  1878.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1879.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1880.     yystate = yytable[yystate];
  1881.   else
  1882.     yystate = yydefgoto[yyn - YYNTBASE];
  1883.  
  1884.   goto yynewstate;
  1885.  
  1886. yyerrlab:   /* here on detecting error */
  1887.  
  1888.   if (! yyerrstatus)
  1889.     /* If not already recovering from an error, report this error.  */
  1890.     {
  1891.       ++yynerrs;
  1892.  
  1893. #ifdef YYERROR_VERBOSE
  1894.       yyn = yypact[yystate];
  1895.  
  1896.       if (yyn > YYFLAG && yyn < YYLAST)
  1897.     {
  1898.       int size = 0;
  1899.       char *msg;
  1900.       int x, count;
  1901.  
  1902.       count = 0;
  1903.       /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
  1904.       for (x = (yyn < 0 ? -yyn : 0);
  1905.            x < (sizeof(yytname) / sizeof(char *)); x++)
  1906.         if (yycheck[x + yyn] == x)
  1907.           size += strlen(yytname[x]) + 15, count++;
  1908.       msg = (char *) malloc(size + 15);
  1909.       if (msg != 0)
  1910.         {
  1911.           strcpy(msg, "parse error");
  1912.  
  1913.           if (count < 5)
  1914.         {
  1915.           count = 0;
  1916.           for (x = (yyn < 0 ? -yyn : 0);
  1917.                x < (sizeof(yytname) / sizeof(char *)); x++)
  1918.             if (yycheck[x + yyn] == x)
  1919.               {
  1920.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1921.             strcat(msg, yytname[x]);
  1922.             strcat(msg, "'");
  1923.             count++;
  1924.               }
  1925.         }
  1926.           yyerror(msg);
  1927.           free(msg);
  1928.         }
  1929.       else
  1930.         yyerror ("parse error; also virtual memory exceeded");
  1931.     }
  1932.       else
  1933. #endif /* YYERROR_VERBOSE */
  1934.     yyerror("parse error");
  1935.     }
  1936.  
  1937.   goto yyerrlab1;
  1938. yyerrlab1:   /* here on error raised explicitly by an action */
  1939.  
  1940.   if (yyerrstatus == 3)
  1941.     {
  1942.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1943.  
  1944.       /* return failure if at end of input */
  1945.       if (yychar == YYEOF)
  1946.     YYABORT;
  1947.  
  1948. #if YYDEBUG != 0
  1949.       if (yydebug)
  1950.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1951. #endif
  1952.  
  1953.       yychar = YYEMPTY;
  1954.     }
  1955.  
  1956.   /* Else will try to reuse lookahead token
  1957.      after shifting the error token.  */
  1958.  
  1959.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1960.  
  1961.   goto yyerrhandle;
  1962.  
  1963. yyerrdefault:  /* current state does not do anything special for the error token. */
  1964.  
  1965. #if 0
  1966.   /* This is wrong; only states that explicitly want error tokens
  1967.      should shift them.  */
  1968.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1969.   if (yyn) goto yydefault;
  1970. #endif
  1971.  
  1972. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1973.  
  1974.   if (yyssp == yyss) YYABORT;
  1975.   yyvsp--;
  1976.   yystate = *--yyssp;
  1977. #ifdef YYLSP_NEEDED
  1978.   yylsp--;
  1979. #endif
  1980.  
  1981. #if YYDEBUG != 0
  1982.   if (yydebug)
  1983.     {
  1984.       short *ssp1 = yyss - 1;
  1985.       fprintf (stderr, "Error: state stack now");
  1986.       while (ssp1 != yyssp)
  1987.     fprintf (stderr, " %d", *++ssp1);
  1988.       fprintf (stderr, "\n");
  1989.     }
  1990. #endif
  1991.  
  1992. yyerrhandle:
  1993.  
  1994.   yyn = yypact[yystate];
  1995.   if (yyn == YYFLAG)
  1996.     goto yyerrdefault;
  1997.  
  1998.   yyn += YYTERROR;
  1999.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  2000.     goto yyerrdefault;
  2001.  
  2002.   yyn = yytable[yyn];
  2003.   if (yyn < 0)
  2004.     {
  2005.       if (yyn == YYFLAG)
  2006.     goto yyerrpop;
  2007.       yyn = -yyn;
  2008.       goto yyreduce;
  2009.     }
  2010.   else if (yyn == 0)
  2011.     goto yyerrpop;
  2012.  
  2013.   if (yyn == YYFINAL)
  2014.     YYACCEPT;
  2015.  
  2016. #if YYDEBUG != 0
  2017.   if (yydebug)
  2018.     fprintf(stderr, "Shifting error token, ");
  2019. #endif
  2020.  
  2021.   *++yyvsp = yylval;
  2022. #ifdef YYLSP_NEEDED
  2023.   *++yylsp = yylloc;
  2024. #endif
  2025.  
  2026.   yystate = yyn;
  2027.   goto yynewstate;
  2028. }
  2029. #line 953 "ftpcmd.y"
  2030.  
  2031.  
  2032. extern jmp_buf errcatch;
  2033.  
  2034. struct tab *
  2035. lookup(p, cmd)
  2036.     register struct tab *p;
  2037.     char *cmd;
  2038. {
  2039.  
  2040.     for (; p->name != NULL; p++)
  2041.         if (strcmp(cmd, p->name) == 0)
  2042.             return (p);
  2043.     return (0);
  2044. }
  2045.  
  2046. #include <arpa/telnet.h>
  2047.  
  2048. /*
  2049.  * getline - a hacked up version of fgets to ignore TELNET escape codes.
  2050.  */
  2051. char *
  2052. getline(s, n, iop)
  2053.     char *s;
  2054.     register FILE *iop;
  2055. {
  2056.     register c;
  2057.     register char *cs;
  2058.  
  2059.     cs = s;
  2060. /* tmpline may contain saved command from urgent mode interruption */
  2061.     for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
  2062.         *cs++ = tmpline[c];
  2063.         if (tmpline[c] == '\n') {
  2064.             *cs++ = '\0';
  2065.             if (debug)
  2066.                 syslog(LOG_DEBUG, "command: %s", s);
  2067.             tmpline[0] = '\0';
  2068.             return(s);
  2069.         }
  2070.         if (c == 0)
  2071.             tmpline[0] = '\0';
  2072.     }
  2073.     while ((c = getc(iop)) != EOF) {
  2074.         c &= 0377;
  2075.         if (c == IAC) {
  2076.             if ((c = getc(iop)) != EOF) {
  2077.             c &= 0377;
  2078.             switch (c) {
  2079.             case WILL:
  2080.             case WONT:
  2081.                 c = getc(iop);
  2082.                 printf("%c%c%c", IAC, DONT, 0377&c);
  2083.                 (void) fflush(stdout);
  2084.                 continue;
  2085.             case DO:
  2086.             case DONT:
  2087.                 c = getc(iop);
  2088.                 printf("%c%c%c", IAC, WONT, 0377&c);
  2089.                 (void) fflush(stdout);
  2090.                 continue;
  2091.             case IAC:
  2092.                 break;
  2093.             default:
  2094.                 continue;   /* ignore command */
  2095.             }
  2096.             }
  2097.         }
  2098.         *cs++ = c;
  2099.         if (--n <= 0 || c == '\n')
  2100.             break;
  2101.     }
  2102.     if (c == EOF && cs == s)
  2103.         return (NULL);
  2104.     *cs++ = '\0';
  2105.     if (debug)
  2106.         syslog(LOG_DEBUG, "command: %s", s);
  2107.     return (s);
  2108. }
  2109.  
  2110. static void
  2111. toolong()
  2112. {
  2113.     time_t now;
  2114.  
  2115.     reply(421,
  2116.       "Timeout (%d seconds): closing control connection.", timeout);
  2117.     (void) time(&now);
  2118.     if (logging) {
  2119.         syslog(LOG_INFO,
  2120.             "User %s timed out after %d seconds at %.24s",
  2121.             (pw ? pw -> pw_name : "unknown"), timeout, ctime(&now));
  2122.     }
  2123.     dologout(1);
  2124. }
  2125.  
  2126. yylex()
  2127. {
  2128.     static int cpos, state;
  2129.     register char *cp, *cp2;
  2130.     register struct tab *p;
  2131.     int n;
  2132.     char c, *copy();
  2133.  
  2134.     for (;;) {
  2135.         switch (state) {
  2136.  
  2137.         case CMD:
  2138.             (void) signal(SIGALRM, toolong);
  2139.             (void) alarm((unsigned) timeout);
  2140.             if (is_shutdown(!logged_in) != 0) {
  2141.                 reply(221, "Server shutting down.  Goodbye.");
  2142.                 dologout(0);
  2143.             }
  2144. #ifdef SETPROCTITLE
  2145.             setproctitle("%s: IDLE", proctitle);
  2146. #endif
  2147.             if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
  2148.                 reply(221, "You could at least say goodbye.");
  2149.                 dologout(0);
  2150.             }
  2151.             (void) alarm(0);
  2152. #ifdef SETPROCTITLE
  2153.             if (strncasecmp(cbuf, "PASS", 4) != 0 &&
  2154.                 strncasecmp(cbuf, "SITE GPASS", 10) != 0)
  2155.                 setproctitle("%s: %s", proctitle, cbuf);
  2156. #endif /* SETPROCTITLE */
  2157.             if ((cp = strchr(cbuf, '\r'))) {
  2158.                 *cp++ = '\n';
  2159.                 *cp = '\0';
  2160.             }
  2161.             if ((cp = strpbrk(cbuf, " \n")))
  2162.                 cpos = cp - cbuf;
  2163.             if (cpos == 0)
  2164.                 cpos = 4;
  2165.             c = cbuf[cpos];
  2166.             cbuf[cpos] = '\0';
  2167.             upper(cbuf);
  2168.             p = lookup(cmdtab, cbuf);
  2169.             cbuf[cpos] = c;
  2170.             if (p != 0) {
  2171.                 if (p->implemented == 0) {
  2172.                     nack(p->name);
  2173.                     longjmp(errcatch,0);
  2174.                     /* NOTREACHED */
  2175.                 }
  2176.                 state = p->state;
  2177.                 yylval.String = p->name;
  2178.                 return (p->token);
  2179.             }
  2180.             break;
  2181.  
  2182.         case SITECMD:
  2183.             if (cbuf[cpos] == ' ') {
  2184.                 cpos++;
  2185.                 return (SP);
  2186.             }
  2187.             cp = &cbuf[cpos];
  2188.             if ((cp2 = strpbrk(cp, " \n")))
  2189.                 cpos = cp2 - cbuf;
  2190.             c = cbuf[cpos];
  2191.             cbuf[cpos] = '\0';
  2192.             upper(cp);
  2193.             p = lookup(sitetab, cp);
  2194.             cbuf[cpos] = c;
  2195.             if (p != 0) {
  2196.                 if (p->implemented == 0) {
  2197.                     state = CMD;
  2198.                     nack(p->name);
  2199.                     longjmp(errcatch,0);
  2200.                     /* NOTREACHED */
  2201.                 }
  2202.                 state = p->state;
  2203.                 yylval.String = p->name;
  2204.                 return (p->token);
  2205.             }
  2206.             state = CMD;
  2207.             break;
  2208.  
  2209.         case OSTR:
  2210.             if (cbuf[cpos] == '\n') {
  2211.                 state = CMD;
  2212.                 return (CRLF);
  2213.             }
  2214.             /* FALLTHROUGH */
  2215.  
  2216.         case STR1:
  2217.         case ZSTR1:
  2218.         dostr1:
  2219.             if (cbuf[cpos] == ' ') {
  2220.                 cpos++;
  2221.                 state = state == OSTR ? STR2 : ++state;
  2222.                 return (SP);
  2223.             }
  2224.             break;
  2225.  
  2226.         case ZSTR2:
  2227.             if (cbuf[cpos] == '\n') {
  2228.                 state = CMD;
  2229.                 return (CRLF);
  2230.             }
  2231.             /* FALLTHROUGH */
  2232.  
  2233.         case STR2:
  2234.             cp = &cbuf[cpos];
  2235.             n = strlen(cp);
  2236.             cpos += n - 1;
  2237.             /*
  2238.              * Make sure the string is nonempty and \n terminated.
  2239.              */
  2240.             if (n > 1 && cbuf[cpos] == '\n') {
  2241.                 cbuf[cpos] = '\0';
  2242.                 yylval.String = copy(cp);
  2243.                 cbuf[cpos] = '\n';
  2244.                 state = ARGS;
  2245.                 return (STRING);
  2246.             }
  2247.             break;
  2248.  
  2249.         case NSTR:
  2250.             if (cbuf[cpos] == ' ') {
  2251.                 cpos++;
  2252.                 return (SP);
  2253.             }
  2254.             if (isdigit(cbuf[cpos])) {
  2255.                 cp = &cbuf[cpos];
  2256.                 while (isdigit(cbuf[++cpos]))
  2257.                     ;
  2258.                 c = cbuf[cpos];
  2259.                 cbuf[cpos] = '\0';
  2260.                 yylval.Number = atoi(cp);
  2261.                 cbuf[cpos] = c;
  2262.                 state = STR1;
  2263.                 return (NUMBER);
  2264.             }
  2265.             state = STR1;
  2266.             goto dostr1;
  2267.  
  2268.         case STR3:
  2269.             if (cbuf[cpos] == ' ') {
  2270.                 cpos++;
  2271.                 return (SP);
  2272.             }
  2273.  
  2274.             cp = &cbuf[cpos];
  2275.             cp2 = strpbrk(cp, " \n");
  2276.             if (cp2 != NULL) {
  2277.                 c = *cp2;
  2278.                 *cp2 = '\0';
  2279.             }
  2280.             n = strlen(cp);
  2281.             cpos += n;
  2282.             /*
  2283.              * Make sure the string is nonempty and SP terminated.
  2284.              */
  2285.             if ((cp2 - cp) > 1) {
  2286.                 yylval.String = copy(cp);
  2287.                 cbuf[cpos] = c;
  2288.                 state = OSTR;
  2289.                 return (STRING);
  2290.             }
  2291.             break;
  2292.  
  2293.         case ARGS:
  2294.             if (isdigit(cbuf[cpos])) {
  2295.                 cp = &cbuf[cpos];
  2296.                 while (isdigit(cbuf[++cpos]))
  2297.                     ;
  2298.                 c = cbuf[cpos];
  2299.                 cbuf[cpos] = '\0';
  2300.                 yylval.Number = atoi(cp);
  2301.                 cbuf[cpos] = c;
  2302.                 return (NUMBER);
  2303.             }
  2304.             switch (cbuf[cpos++]) {
  2305.  
  2306.             case '\n':
  2307.                 state = CMD;
  2308.                 return (CRLF);
  2309.  
  2310.             case ' ':
  2311.                 return (SP);
  2312.  
  2313.             case ',':
  2314.                 return (COMMA);
  2315.  
  2316.             case 'A':
  2317.             case 'a':
  2318.                 return (A);
  2319.  
  2320.             case 'B':
  2321.             case 'b':
  2322.                 return (B);
  2323.  
  2324.             case 'C':
  2325.             case 'c':
  2326.                 return (C);
  2327.  
  2328.             case 'E':
  2329.             case 'e':
  2330.                 return (E);
  2331.  
  2332.             case 'F':
  2333.             case 'f':
  2334.                 return (F);
  2335.  
  2336.             case 'I':
  2337.             case 'i':
  2338.                 return (I);
  2339.  
  2340.             case 'L':
  2341.             case 'l':
  2342.                 return (L);
  2343.  
  2344.             case 'N':
  2345.             case 'n':
  2346.                 return (N);
  2347.  
  2348.             case 'P':
  2349.             case 'p':
  2350.                 return (P);
  2351.  
  2352.             case 'R':
  2353.             case 'r':
  2354.                 return (R);
  2355.  
  2356.             case 'S':
  2357.             case 's':
  2358.                 return (S);
  2359.  
  2360.             case 'T':
  2361.             case 't':
  2362.                 return (T);
  2363.  
  2364.             }
  2365.             break;
  2366.  
  2367.         default:
  2368.             fatal("Unknown state in scanner.");
  2369.         }
  2370.         yyerror((char *)NULL);
  2371.         state = CMD;
  2372.         longjmp(errcatch,0);
  2373.     }
  2374. }
  2375.  
  2376. upper(s)
  2377.     register char *s;
  2378. {
  2379.     while (*s != '\0') {
  2380.         if (islower(*s))
  2381.             *s = toupper(*s);
  2382.         s++;
  2383.     }
  2384. }
  2385.  
  2386. char *
  2387. copy(s)
  2388.     char *s;
  2389. {
  2390.     char *p;
  2391.  
  2392.     p = (char *) malloc((unsigned) strlen(s) + 1);
  2393.     if (p == NULL)
  2394.         fatal("Ran out of memory.");
  2395.     (void) strcpy(p, s);
  2396.     return (p);
  2397. }
  2398.  
  2399. help(ctab, s)
  2400.     struct tab *ctab;
  2401.     char *s;
  2402. {
  2403.     register struct tab *c;
  2404.     register int width, NCMDS;
  2405.     char *type;
  2406.  
  2407.     if (ctab == sitetab)
  2408.         type = "SITE ";
  2409.     else
  2410.         type = "";
  2411.     width = 0, NCMDS = 0;
  2412.     for (c = ctab; c->name != NULL; c++) {
  2413.         int len = strlen(c->name);
  2414.  
  2415.         if (len > width)
  2416.             width = len;
  2417.         NCMDS++;
  2418.     }
  2419.     width = (width + 8) &~ 7;
  2420.     if (s == 0) {
  2421.         register int i, j, w;
  2422.         int columns, lines;
  2423.  
  2424.         lreply(214, "The following %scommands are recognized %s.",
  2425.             type, "(* =>'s unimplemented)");
  2426.         columns = 76 / width;
  2427.         if (columns == 0)
  2428.             columns = 1;
  2429.         lines = (NCMDS + columns - 1) / columns;
  2430.         for (i = 0; i < lines; i++) {
  2431.             printf("   ");
  2432.             for (j = 0; j < columns; j++) {
  2433.                 c = ctab + j * lines + i;
  2434.                 printf("%s%c", c->name,
  2435.                     c->implemented ? ' ' : '*');
  2436.                 if (c + lines >= &ctab[NCMDS])
  2437.                     break;
  2438.                 w = strlen(c->name) + 1;
  2439.                 while (w < width) {
  2440.                     putchar(' ');
  2441.                     w++;
  2442.                 }
  2443.             }
  2444.             printf("\r\n");
  2445.         }
  2446.         (void) fflush(stdout);
  2447.         reply(214, "Direct comments to ftp-bugs@%s.", hostname);
  2448.         return;
  2449.     }
  2450.     upper(s);
  2451.     c = lookup(ctab, s);
  2452.     if (c == (struct tab *)NULL) {
  2453.         reply(502, "Unknown command %s.", s);
  2454.         return;
  2455.     }
  2456.     if (c->implemented)
  2457.         reply(214, "Syntax: %s%s %s", type, c->name, c->help);
  2458.     else
  2459.         reply(214, "%s%-*s\t%s; unimplemented.", type, width,
  2460.             c->name, c->help);
  2461. }
  2462.  
  2463. sizecmd(filename)
  2464. char *filename;
  2465. {
  2466.     switch (type) {
  2467.     case TYPE_L:
  2468.     case TYPE_I: {
  2469.         struct stat stbuf;
  2470.         if (stat(filename, &stbuf) < 0 ||
  2471.             (stbuf.st_mode&S_IFMT) != S_IFREG)
  2472.             reply(550, "%s: not a plain file.", filename);
  2473.         else
  2474.             reply(213, "%lu", stbuf.st_size);
  2475.         break;}
  2476.     case TYPE_A: {
  2477.         FILE *fin;
  2478.         register int c;
  2479.         register long count;
  2480.         struct stat stbuf;
  2481.         fin = fopen(filename, "r");
  2482.         if (fin == NULL) {
  2483.             perror_reply(550, filename);
  2484.             return;
  2485.         }
  2486.         if (fstat(fileno(fin), &stbuf) < 0 ||
  2487.             (stbuf.st_mode&S_IFMT) != S_IFREG) {
  2488.             reply(550, "%s: not a plain file.", filename);
  2489.             (void) fclose(fin);
  2490.             return;
  2491.         }
  2492.  
  2493.         count = 0;
  2494.         while((c=getc(fin)) != EOF) {
  2495.             if (c == '\n')  /* will get expanded to \r\n */
  2496.                 count++;
  2497.             count++;
  2498.         }
  2499.         (void) fclose(fin);
  2500.  
  2501.         reply(213, "%ld", count);
  2502.         break;}
  2503.     default:
  2504.         reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
  2505.     }
  2506. }
  2507.  
  2508. site_exec(cmd)
  2509. char *cmd;
  2510. {
  2511.     char buf[MAXPATHLEN];
  2512.     char *sp = (char *) strchr(cmd, ' '), *slash, *t;
  2513.     FILE *cmdf, *ftpd_popen();
  2514.  
  2515.     /* sanitize the command-string */
  2516.     
  2517.     if (sp == 0)  {
  2518.         while ((slash = strchr (cmd, '/')) != 0)
  2519.             cmd = slash + 1;
  2520.     } else {
  2521.         while (sp && (slash = (char *) strchr(cmd, '/')) 
  2522.                && (slash < sp))
  2523.             cmd = slash+1;
  2524.     }
  2525.     
  2526.     for (t = cmd;  *t && !isspace(*t);  t++) {
  2527.         if (isupper(*t)) {
  2528.             *t = tolower(*t);
  2529.         }
  2530.     }
  2531.  
  2532.     /* build the command */
  2533.     if (strlen(_PATH_EXECPATH) + strlen(cmd) + 1 > sizeof(buf))
  2534.         return;
  2535.     sprintf(buf, "%s/%s", _PATH_EXECPATH, cmd);
  2536.  
  2537.     cmdf = ftpd_popen(buf, "r", 0);
  2538.     if (!cmdf) {
  2539.         perror_reply(550, cmd);
  2540.         if (log_commands)
  2541.             syslog(LOG_INFO, "SITE EXEC (FAIL: %m): %s", cmd);
  2542.     } else {
  2543.         int lines = 0;
  2544.  
  2545.         lreply(200, cmd);
  2546.         while (fgets(buf, sizeof buf, cmdf)) {
  2547.             int len = strlen(buf);
  2548.  
  2549.             if (len>0 && buf[len-1]=='\n')
  2550.                 buf[--len] = '\0';
  2551.             lreply(200, buf);
  2552.             if (++lines >= 20) {
  2553.                 lreply(200, "*** Truncated ***");
  2554.                 break;
  2555.             }
  2556.         }
  2557.         reply(200, " (end of '%s')", cmd);
  2558.         if (log_commands)
  2559.             syslog(LOG_INFO, "SITE EXEC (lines: %d): %s", lines, cmd);
  2560.         ftpd_pclose(cmdf);
  2561.     }
  2562. }
  2563.  
  2564. alias (s)
  2565. char *s;
  2566. {
  2567.     struct aclmember *entry = NULL;
  2568.  
  2569.     if (s != (char *)NULL) {
  2570.         while (getaclentry("alias", &entry) && ARG0 && ARG1 != NULL)
  2571.             if (!strcmp(ARG0, s)) {
  2572.                 reply (214, "%s is an alias for %s.", ARG0, ARG1);
  2573.                 return;
  2574.             }
  2575.         reply (502, "Unknown alias %s.", s);
  2576.         return;
  2577.     }
  2578.  
  2579.     lreply(214, "The following aliases are available.");
  2580.  
  2581.     while (getaclentry("alias", &entry) && ARG0 && ARG1 != NULL)
  2582.         printf ("   %-8s %s\r\n", ARG0, ARG1);
  2583.     (void) fflush (stdout);
  2584.  
  2585.     reply(214, "");
  2586. }
  2587.  
  2588. cdpath ()
  2589. {
  2590.     struct aclmember *entry = NULL;
  2591.  
  2592.     lreply(214, "The cdpath is:");
  2593.     while (getaclentry("cdpath", &entry) && ARG0 != NULL)
  2594.         printf ("  %s\r\n", ARG0);
  2595.     (void) fflush (stdout);
  2596.     reply(214, "");
  2597. }
  2598.  
  2599. void
  2600. print_groups()
  2601. {
  2602.     gid_t  groups[NGROUPS_MAX];
  2603.     int    ngroups = 0;
  2604.  
  2605.     if ( (ngroups = getgroups(NGROUPS_MAX, groups)) < 0 ) {
  2606.         return;
  2607.     }
  2608.  
  2609.     lreply(214, "Group membership is:");
  2610.     ngroups--;
  2611.  
  2612.     for (; ngroups >= 0; ngroups--)
  2613.         lreply(214, "  %d", groups[ngroups]);
  2614.  
  2615.     (void) fflush (stdout);
  2616.     reply(214, "");
  2617. }
  2618.